<br />
<div class="linkStyle1">
	<a href="<?php echo site_url();?>/price_rule/add">Create New Rules</a>
</div>

<div class="titleStyle1">Price Rules</div>
<?php if (sizeof($result)> 0) {

	echo '<div class="waitingTable ">';
	echo '<table id="resultTable">';
	echo '<tr>';
	echo '<td style="display:none;"></td>';
	echo '<td>';
	echo 'current stock per mininum stock (percentage)';
	echo '</td>';
	echo '<td>';
	echo 'Discount';
	echo '</td>';
	echo '<td>';
	echo 'Edit';
	echo '</td>';
	echo '<td>';
	echo 'Delete';
	echo '</td>';
	echo '</tr>';

	foreach ($result as $rule){
		echo '<tr>';
		echo '<td style="display:none;" class="id">';
		echo $rule->price_rule_id;
		echo '</td>';
		echo '<td class="clk">';
		echo $rule->price_rule_percent . '%';
		echo '</td>';
		echo '<td class="clk">';
		echo $rule->price_rule_discount . '%';
		echo '</td>';
		echo '<td style="text-align:center;">';
		echo '<a class="downloadButton" href="'. site_url().'/price_rule/update/'.$rule->price_rule_id.'">Edit</a>';
		echo '</td>';
		echo '<td style="text-align:center;">';
		echo '<input type="button" value ="Delete" class="redButton" name="btn" />';
		echo '</td>';
		echo '</tr>';
	}

	echo '</table>';
	echo '</div>';

}else{
	echo '<div class="information">';
	echo 'no price rule found.';
	echo '</div>';
}
?>

<script>

	$(function () {

		$('#resultTable .redButton').click(function(){
	    	var price_rule_id = $(this).parent().siblings('.id').text();
	    	var cell = $(this).parent();
	    	cell.html('<?php echo img(array('src'=>asset_url().'images/load.gif', 'alt'=> 'home')); ?>');
			var jqxhr = $.post( "price_rule/delete", {price_rule_id: price_rule_id})
			.done(function(data) {
				if (data == '1'){
					cell.html('<label style="color:#00a10b;">Success</label>');
					var chk = cell.siblings('.chk').children();
					chk.attr("disabled", true);
					chk.prop("checked", false);
					chk.removeClass('request');
				}else
					cell.html('<label style="color:red;">fail</label>');
			})
			.fail(function() {
				cell.html('<label style="color:red;">fail</label>');
			});

	    });
	});

</script>
